<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
     <#assign base=request.contextPath  />
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <link rel="stylesheet" href="${base}/frame/layui/css/layui.css" media="all">
    <script src="${base}/frame/layui/layui.js"></script>
    <script src="${base}/js/jquery-1.8.3.min.js"></script>
    <title>修改密码</title>
    <style>
        .signin {
            margin: 0 auto;
            text-align: center;
            margin-top: 200px;
        }

        .signin h1 {
            text-align: center;
            padding-bottom: 10px;
        }

        .layui-btn {
            width: 300px;
        }

        .layui-input-block {
            width: 300px;
            margin: 0 auto;
        }
    </style>
</head>


<body>
<div class="signin-p">
    <div class="signin">
        <h1>修改密码</h1>
        <form class="layui-form" action="">
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <input type="password" id="oldpassword" required lay-verify="required" placeholder="请输入旧密码"
                           autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <input type="password" id="newpassword" required lay-verify="required" placeholder="请输入新密码"
                           autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-filter="formDemo" onclick="submission()" type="button">提交</button>
                </div>
            </div>
        </form>
    </div>
</div>
</body>

</html>
<script>


    layui.use('form', function () {
        var form = layui.form;

    });

    function submission() {
        //session中密码
        var sessionPassword = '${userInfo.password}';
        var oldPassword = $("#oldpassword").val();
        var newPassword = $("#newpassword").val();

        if(sessionPassword!=oldPassword){
            layer.msg("旧密码错误")
            return;
        }

        if(oldPassword==newPassword){
            layer.msg("旧密码不能和新密码一致")
            return;
        }
        if(oldPassword==""){
            layer.msg("旧密码不能为空")
            return;
        }
        if(newPassword==""){
            layer.msg("新密码不能为空")
            return;
        }

        var jsonDate = {
            id:'${userInfo.id}',
            password:newPassword
        }


        $.ajax({
            type: "POST",
            contentType: "application/json;charset=UTF-8",
            url: "${base}/admin/userInfo/updatePassword",
            data: JSON.stringify(jsonDate),
            success: function (data) {
                if (data.code === 0) {
                    layer.msg(data.msg)
                    setTimeout(function () {
                        window.location.href = "${base}/admin/userInfo/index.html"

                    }, 500)
                } else {
                    layer.msg(data.msg)
                }
            }
        });


    }




</script>